#include<iostream>
#include<omp.h>
#include<sys/time.h>
using namespace std;
const int N=5000;
float m[N][N];
const int NUM_THREADS=7;
void m_reset()
{

        for(int i=0;i<N;i++)
        {

                for(int j=0;j<i;j++)
                        m[i][j]=0;
                m[i][i]=1.0;
                for(int j=i+1;j<N;j++)                                                                                                                  mat[i][j]=rand()%100;
        }
        for(int k=0;k<N;k++)
                for(int i=k+1;i<N;i++)
                        for(int j=0;j<N;j++)
                                m[i][j]+=m[k][j];
}

void func(){

        int i,j,k;
        float tmp;
        bool parallel=true;
#pragma omp parallel if(parallel), num_threads(NUM_THREADS), private(i, j, k, tmp)
        for(k = 0; k < N; ++k){
#pragma omp single
                {
                        tmp = m[k][k];
                        for(j = k + 1; j < N; ++j){
                                m[k][j] = m[k][j]/tmp;
                        }
                        m[k][k] = 1.0;
                }
#pragma omp for
                for(i = k + 1; i < N; ++i){
                        tmp = m[i][k];
                        for(j = k + 1; j < N; ++j){
                                m[i][ j ] = m[i][j]-tmp*m[k][j];

                        }
                                        m[i][k] = 0.0;
                                }

        }
}
int main()
{
        m_reset();
        struct  timeval   tv_begin,tv_end;
        unsigned  long openmp_time;

        gettimeofday(&tv_begin,NULL);

        func();
       gettimeofday(&tv_end,NULL);
        openmp_time=1000000 * (tv_end.tv_sec-tv_begin.tv_sec)+ tv_end.tv_usec-tv_begin.tv_usec;
        cout<<"openmp_time:"<<openmp_time<<endl;
}